#include <iostream>
#include <cmath>
using namespace std;

/*bool isPrime(unsigned int num)
{
	for (unsigned int x = 2; x < num; ++x)
	{
		if (num % x == 0)
			return false;
	}

	return true;
}*/

bool isPrime( unsigned int num )
{
	if ( num == 1 )
	{
		return false;
	}
	else if  ( num < 4 ) // for 2 and 3
	{
		return true;
	}
	else if ( num % 2 == 0 )
	{
		return false;
	}
	else if ( num < 9 ) // for 5 and 7
	{
		return true;
	}
	else if ( num % 3 == 0 )
	{
		return false;
	}
	else
	{
		unsigned int limit = floor( sqrt( num * 1.0f ));
		unsigned int factor = 5;

		while ( factor <= limit )
		{
			if ( num % factor == 0 )
			{
				return false;
			}
			if ( num % ( factor + 2 ) == 0 )
			{
				return false;
			}

			factor += 6;
		}

		return true;
	}
}

int main()
{
	int count = 0;
	unsigned int num = 2;

	while (count < 10001)
	{
		if (isPrime(num))
		{
			++count;

			if ( count == 10001)
			{
				cout << "10001 is: " << num << endl;
			}

		}

		++num;
	}
}